<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function demo(num) {
            // 临界条件
            if (num === 1 || num === 2) {
                // 前两项都是1
                return 1;
            }
            // 当前项等于前两项的和
            return demo(num-1) + demo(num-2)
        }

        var result = demo(1);
        var result1 = demo(2);
        var result2 = demo(3);

        // demo(3-1) + demo(3-2)  ==>  1+1 = 2
        var result3 = demo(4);
        console.log(result)
        console.log(result1)
        console.log(result2)
        console.log(result3)

    </script>
</body>
</html>